package com.yjc.drygoods.order.vo;

import com.yjc.common.to.CouponTo;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单模型
 *
 * @author yjc
 * @create 2022-09-23 22:47
 */
public class OrderConfirmVo {
    /**
     * 收货地址
     */
    @Setter
    @Getter
    List<MemberAddressVo> address;

    /**
     * 所有选中的购物项
     */
    @Setter
    @Getter
    List<OrderItemVo> orderItems;

    /**
     * 优惠券信息
     */
    @Setter
    @Getter
    List<CouponTo> integration;

    /**
     * 购物积分
     */
    @Setter
    @Getter
    Integer buyIntegration;

    /**
     * 防重令牌
     */
    @Setter
    @Getter
    String orderToken;

    /**
     * 对应skuId是否有货
     */
    @Setter
    @Getter
    Map<Long, Boolean> hasStock;

    /**
     * 订单总额
     */
    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if (orderItems != null && orderItems.size() > 0) {
            for (OrderItemVo orderItem : orderItems) {
                BigDecimal multiply = orderItem.getPrice().multiply(new BigDecimal(orderItem.getCount().toString()));
                total = total.add(multiply);
            }
        }
        return total;
    }

    /**
     * 应付价格
     */
    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    /**
     * 商品总数量
     */
    Integer count;

    public Integer getCount() {
        Integer counts = 0;
        if (orderItems != null && orderItems.size() > 0) {
            for (OrderItemVo orderItem : orderItems) {
                counts += orderItem.getCount();
            }
        }
        return counts;
    }
}
